using System;

namespace Lazy.Captcha.Core.RateLimit
{
    /// <summary>
    /// 频率限制检查结果
    /// </summary>
    public class RateLimitResult
    {
        /// <summary>
        /// 是否允许请求
        /// </summary>
        public bool IsAllowed { get; set; }

        /// <summary>
        /// 剩余请求次数
        /// </summary>
        public int RemainingRequests { get; set; }

        /// <summary>
        /// 下次重置时间
        /// </summary>
        public DateTime? ResetTime { get; set; }

        /// <summary>
        /// 时间窗口（秒）
        /// </summary>
        public int WindowSeconds { get; set; }

        /// <summary>
        /// 最大请求次数
        /// </summary>
        public int MaxRequests { get; set; }

        /// <summary>
        /// 限制键
        /// </summary>
        public string Key { get; set; }

        /// <summary>
        /// 创建允许的结果
        /// </summary>
        public static RateLimitResult Allowed(string key, int remainingRequests, DateTime? resetTime, int windowSeconds, int maxRequests)
        {
            return new RateLimitResult
            {
                IsAllowed = true,
                Key = key,
                RemainingRequests = remainingRequests,
                ResetTime = resetTime,
                WindowSeconds = windowSeconds,
                MaxRequests = maxRequests
            };
        }

        /// <summary>
        /// 创建拒绝的结果
        /// </summary>
        public static RateLimitResult Denied(string key, int remainingRequests, DateTime? resetTime, int windowSeconds, int maxRequests)
        {
            return new RateLimitResult
            {
                IsAllowed = false,
                Key = key,
                RemainingRequests = remainingRequests,
                ResetTime = resetTime,
                WindowSeconds = windowSeconds,
                MaxRequests = maxRequests
            };
        }
    }
}
